package com.egao.common.module.workLog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.core.exception.ParameterException;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.workLog.entity.WorkLogItem;
import com.egao.common.module.workLog.mapper.WorkLogItemMapper;
import com.egao.common.module.workLog.service.WorkLogItemService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务实现类
 *
 * @author shu
 */
@Service
public class WorkLogItemServiceImpl extends ServiceImpl<WorkLogItemMapper, WorkLogItem> implements WorkLogItemService {

    @Override
    public JsonResult add (WorkLogItem workLogItem) {
        if (workLogItem ==null){
            throw new ParameterException("参数对象为空");
        }

        baseMapper.insert(workLogItem);
        return JsonResult.ok("添加成功");
    }

    @Override
    public JsonResult update(WorkLogItem workLogItem) {
        if (workLogItem == null) {
            throw new ParameterException("参数对象为空");
        }

        if (workLogItem.getId() == null) {
            throw new ParameterException("参数对象id为空");
        }

        baseMapper.updateById(workLogItem);
        return JsonResult.ok("修改成功");
    }

    @Override
    public JsonResult delete(List<Integer> ids) {
        if (ids != null && ids.size() > 0) {
            this.baseMapper.deleteBatchIds(ids);
        }
        return JsonResult.ok("删除成功");
    }

    @Override
    public JsonResult read(Integer id) {
        if (id == null) {
            throw new ParameterException("参数对象为空");
        }

        WorkLogItem workLogItem = baseMapper.selectById(id);
        return JsonResult.ok().setData(workLogItem);
    }

}